package cloud.maque.admin.impl;

import cloud.maque.admin.domain.entity.MqComboMenu;
import cloud.maque.admin.mapper.MqComboMenuMapper;
import cloud.maque.admin.service.MqComboMenuService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhuyf
 * @date 2023/5/13 18:00
 */
@Service
public class MqComboMenuServiceImpl
        extends ServiceImpl<MqComboMenuMapper, MqComboMenu>
        implements MqComboMenuService {


    @Override
    @Transactional
    public List<MqComboMenu> saveMenu(String comboId, List<String> menuids) {

        QueryWrapper<MqComboMenu> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(MqComboMenu::getComboId, comboId);
        this.remove(queryWrapper);

        List<MqComboMenu> menuList = new ArrayList<>();
        for (String id : menuids) {
            MqComboMenu menu = new MqComboMenu();
            menu.setComboId(comboId);
            menu.setMenuId(id);
            menuList.add(menu);
        }

        this.saveBatch(menuList);

        return menuList;
    }

    @Override
    public List<MqComboMenu> getMenus(String comboId) {
        QueryWrapper<MqComboMenu> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(MqComboMenu::getComboId, comboId);
        return this.list(queryWrapper);
    }
}
